<template>
	<view>
		<view class="top"></view>
		<view class="question">
			<text style="font-weight: 800;">第{{current + 1}}问:{{currentQestion.question}}</text>
		</view>
		<view class="uni-list" style="width: 100%; background-color:rgba(99,99,99,0);margin: 10upx; height: 600upx; overflow: hidden;">
            <checkbox-group v-if="refresh">
                <label class="uni-list-cell uni-list-cell-pd" v-for="item in answers" :key="item.key">
                    <view>
                        <checkbox name="checkPro" :value="item.answer" :checked="item.checked"/>
						<text style="padding-left: 80upx; font-size: 34upx;">{{item.answer}}</text>
                    </view>
                    
                </label>
            </checkbox-group>
        </view>
	
		<view class="uni-padding-wrap uni-common-mt foot">
			<button type="primary" style="text-indent: 120upx;letter-spacing: 120upx; text-align: center; width: 80%;" @click="onClickItem">提交</button>
		</view>
	</view>
</template>

<script>

	export default {
		components: {
			
		},
		data() {
			return {
				current:0,
				questions: require("../../data/diseases/questions.json"),
				currentQestion: {},
				answers:[],
				labelDataList:'',
				labelList:[],
				isLast: false,
				refresh: false,
			}
		},
		onLoad() {
			this.init();
		},
		methods:{
			onClickItem() {
			    this.nextQuestion();
			},
			getCurrent() {
				let question = {};
				if (this.questions.length) {
					question = this.questions[this.current];
				}
				question.answers.forEach(item => {
					item.checked = false;
				});
				this.currentQestion = question;
				let that = this;
				that.answers.forEach(item=>{
					item.checked = false;
				})
				this.refresh = false;
				this.$nextTick(()=>{
					let question = that.currentQestion;
					this.answers = question.answers;
					this.refresh = true;
				})
				return question;
			},
			init() {
				this.current = 0;
				this.currentQestion = this.getCurrent();
			},
			nextQuestion() {
				this.current ++;
				if (this.isLast) {
					uni.redirectTo({
						url: 'orderDetail'
					});
					return;
				}
				if ( this.current >= this.questions.length - 1) {
					this.isLast = true;
				}
				this.currentQestion = null;
				this.currentQestion = this.getCurrent();
				let that = this;
				that.currentQestion.answers.forEach(item=>{
					item.checked = false;
				})
				that.currentQestion.answers[0].checked = false;
			},
			
			
		}
		
	}
</script>

<style>
	page {
		background-color: #fff;
		background: url(http://yao.hayzon.com/static/replace0823/chinesestyle.png) 100% center/100% no-repeat;
	}

	.top {
		background-color: #f3f2eb;
		height: 5upx;
	}

	.question {
		height: 15%;
		width: 100%;
		margin-top: 5upx;
		/* background-color: #fff; */
		text-align: center;
		padding-top: 130upx;
		padding-bottom: 60upx;
	}

	.question text {
		font-size: 1.3em;
		font-weight: bold;
	}

	.answer {
		height: 80%;
		width: 350upx;
		/* background-color: #fff; */
		display: flex;
		margin: 0 auto;

	}

	.item {
		width: 100upx;
		height: 100upx;
		line-height: 100upx;
		border-radius: 50%;
		/* border: 1px solid #eb6350; */
		text-align: center;
		margin: 30upx;
		background: #fff;
	}

	.foot {
		position: fixed;
		bottom: 80upx;
		width: 100%;
		text-align: center;
		height: 80upx;
		/* box-shadow: 0 0 20upx 0 rgba(0, 0, 0, .5); */
	}

	.foot text {
		font-size: 1.1em;
		color:#eb6350 ;
		line-height: 80upx;
	}
</style>
